package com.caigou.controller;

import com.caigou.bean.cms.param.CommonParam;
import com.caigou.bean.exam.entity.Users;
import com.caigou.component.SnowflakeComponent;
import com.caigou.pojo.*;
import com.caigou.security.utils.CurrentUser;
import com.caigou.service.CommonService;
import com.caigou.util.Result;
import com.caigou.util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Api(value = "公共组件管理器")
@RestController
@RequestMapping("/common")
public class CommonController {

    @Resource
    private CommonService commonService;
    @Resource
    private SnowflakeComponent snowflakeComponent;// 雪花UUID组件

    @ApiOperation("获取数据唯一ID")
    @RequestMapping("/loadUniqueId")
    public Result loadUniqueId(){
        return ResultUtil.success(String.valueOf(snowflakeComponent.getInstance().nextId()));
    }

    @ApiOperation("统一获取字典分类列表")
    @RequestMapping("/loadDictionaryList")
    public Result<List<DictionaryList>> loadDictionaryList(@RequestBody CommonParam param){
        return commonService.loadDictionaryList(param);
    }

    @ApiOperation("获取用户某个页面某个表格的显示隐藏状态")
    @RequestMapping("/loadPageTableData")
    public Result<List<RouterTableColumn>> loadPageTableData(@RequestBody CommonParam param, @CurrentUser Users users){
        return commonService.loadPageTableData(param,users);
    }

    @ApiOperation("更新用户某个页面某个表格的显示隐藏状态")
    @RequestMapping("/saveUserPageTableData")
    public Result saveUserPageTableData(@RequestBody List<CommonParam> params, @CurrentUser Users users){
        return commonService.saveUserPageTableData(params,users);
    }

    @ApiOperation("获取地区字典(单层)")
    @RequestMapping("/loadChinaDictionaryList")
    public Result<List<DictionaryList>> loadChinaDictionaryList(@RequestBody CommonParam param){
        return commonService.loadChinaDictionaryList(param);
    }

    @ApiOperation("获取标题类型字典")
    @RequestMapping("/loadTitleDictionaryList")
    public Result<List<TitleDictionaryList>> loadTitleDictionaryList(@RequestBody CommonParam param){
        return commonService.loadTitleDictionaryList(param);
    }

    @ApiOperation("获取文章审核人员列表")
    @RequestMapping("/loadArticleAuditList")
    public Result<List<ArticleAuditList>> loadArticleAuditList(@RequestBody CommonParam param, @CurrentUser Users users){
        return commonService.loadArticleAuditList(param,users);
    }

    @ApiOperation("获取法规层次字典")
    @RequestMapping("/loadLawLevelDictionaryList")
    public Result<List<LawLevelDictionaryList>> loadLawLevelDictionaryList(){
        return commonService.loadLawLevelDictionaryList();
    }

    @ApiOperation("远程搜索用户列表")
    @RequestMapping("/loadUserListByName")
    public Result<List<ArticleAuditList>> loadUserListByName(@RequestBody CommonParam param){
        return commonService.loadUserListByName(param);
    }

    @RequestMapping("/loadChannelList")
    public Result loadChannelList(@RequestBody CommonParam param){
        return commonService.loadChannelList(param);
    }

    @ApiOperation("获取分站列表")
    @RequestMapping("/loadSubstation")
    public Result loadSubstation(){
        return commonService.loadSubstation();
    }

    @ApiOperation("获取采集源列表")
    @RequestMapping("/loadCollectionList")
    public Result loadCollectionList(){
        return commonService.loadCollectionList();
    }

    @ApiOperation("获取文章新增/修改页可发布频道筛选列表（不包含分站）")
    @RequestMapping("/loadPublishChannelList")
    public Result loadPublishChannelList(){
        return commonService.loadPublishChannelList();
    }
}
